<?php
/**
 * Created by PhpStorm.
 * User: qhzhyt
 * Date: 2018/10/4
 * Time: 19:22
 */

require_once '../conf/conf.php';

if (!isset($_POST['username']) || !isset($_POST['email']) || !isset($_POST['password'])) {
    echo(json_encode(['status' => 0, 'code' => 2]));
    exit(1);
}
$email=$_POST['email'];
if (!validate_email($email)){
    echo(json_encode(['status' => 0, 'code' => 6]));
    exit(1);
}


if($db->has('user',['email'=>$email])){
    //$log->addDebug($db->has('user','email',"email='$email'"));
    echo(json_encode(['status' => 0, 'code' => 3]));
    exit(1);
}

$db->insert('user',['user_name'=>$_POST['username'],'email'=>$email,'password'=>cryptPassword($_POST['password'])]);

$userId=$db->id();

if ($userId!=0){
    echo(json_encode(['status' => 1, 'code' => 1]));
    exit(1);
}
else{
    echo(json_encode(['status' => 0, 'code' => 0]));
    exit(1);
}